import graphfactory from "../graph/graphfactory";
import {LGXEnums}  from "../common/sysenum";

import {CommonSvc}  from "./commonsvc";

import globalConst from "../common/globalConst";

var SelectAllSvc = {}
SelectAllSvc.selectAll = function(dataManager){
    console.log("selectAll*****************");
    let validList = [];
    let tAlllGraphList = dataManager.getAllGraphs();
    let count = tAlllGraphList.length;
    for (let i = 0; i < count; i++) {
        let pGraph = tAlllGraphList[i];
        if (pGraph.getUseful() == 1){
            dataManager.add2SelectList(pGraph);
            pGraph.setSelect(1);
            validList.push(pGraph);
        }
    }
    if (validList.length == 0){
        return ;
    }
    console.log(validList);
    dataManager.setMultiModifyMode(true);
    let mulSelGraph = graphfactory.GraphFactory.createGraphByEnums(0,LGXEnums.LGXGraphType.MultiSel_Rect_Type);
    if (mulSelGraph){
        let mapViewInfo = dataManager.getMapViewInfo();
        mulSelGraph.getLineDef().color.clone(mapViewInfo.backColor.invert());

        let rect = CommonSvc.calGraphsZone(validList);
        let position = mulSelGraph.getPosCopy();
        position.clear();
        position.addPoint(rect.ltPt());
        position.addPoint(rect.lbPt());
        position.addPoint(rect.rbPt());
        position.addPoint(rect.rtPt());
        mulSelGraph.setPos(position);
        mulSelGraph.calScope(1);
        mulSelGraph.setFinish(1);

        mulSelGraph.m_gid = globalConst.GlobalConst.RectSel_GID;
        dataManager.getLayerManager().addGraphToLayer(mulSelGraph, "", -1);
        dataManager.setMulSelRectGraph(mulSelGraph);
        dataManager.add2SelectList(mulSelGraph);
        mulSelGraph.setSelect(1);
    }
}
export{SelectAllSvc} 